package com.vf.admin.client.controller.trip;


import cn.hutool.core.util.ObjectUtil;
import com.vf.admin.client.common.RedisKeys;
import com.vf.admin.client.dto.AppTripDto;
import com.vf.admin.client.service.AppTripService;
import com.vf.admin.client.service.AppUserService;
import com.vf.admin.common.BaseController;
import com.vf.admin.common.Constants;
import com.vf.admin.common.entity.Result;
import com.vf.admin.common.redis.RedisUtil;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.*;
import com.vf.admin.miaodong.service.*;
import com.vf.admin.platform.entity.User;
import com.vf.admin.utils.StringEx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;

import static com.vf.admin.common.Constants.*;
import static com.vf.admin.utils.RandomUtil.getNewFileNameuuid;
import static com.vf.admin.utils.StringEx.isNull;

/**
 * 搭圈管理
 */
@Controller
@RequestMapping("/after/trip")
public class AfterTripController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Resource
    private AppTripService appTripService;

    /**
     * 获取所有用户
     */
    @RequestMapping("/page")
    public String page(SplitPageBean splitPage, Integer status) {
        try {
            Map<String, Object> map = new HashMap<>();
            map.put("status", status);
            List<AppTripDto> maps = appTripService.getAppTripDtoPage(map, splitPage);
            for (AppTripDto dto: maps) {
                if(ObjectUtil.isNotEmpty(dto.getTrippic())){
                    dto.setPicList(Arrays.asList(dto.getTrippic().split(",")));
                }
            }
            Map<Integer, String> statusMap = Constants.getTripStatusMap();
            String k = jsonArray.toJSONString(maps);
            request.setAttribute("list", maps);
            request.setAttribute("splitPage", splitPage);
            request.setAttribute("mapsJsonStr", k);
            request.setAttribute("statusMap", statusMap);
            request.setAttribute("status", status);
            return this.sucess("/web/after/trip/page");
        } catch (Exception e) {
            logger.error("查看搭圈列表异常", e);
            return this.error("系统繁忙");
        }
    }

    /**
     * 账号状态修改
     * @return
     */
    @RequestMapping("/updateStatus")
    @ResponseBody
    public Result updateStatus(Integer id, Integer status) {
        try {
            appTripService.updateStatus(id, status);
            return this.sucessJSON("保存成功");
        } catch (Exception e) {
            logger.error("账号解禁操作异常", e);
            return this.errorJSON("系统繁忙");
        }
    }


}
